<template>
	<view class="container">
		<Head :isBackIcon="false" title="我的" :scrollTop="scrollTop" />
		<view class="first">
			<view style="display: flex;align-items: center;">
				<image :src="userInfo && userInfo.avatar || '../../static/tx.png'" class="firstImg" />
				<view v-if="!userInfo" @click="onNav('/pages/login/index')">登录/注册</view>
				<view class="firstView2" v-else>
					<view class="firstText1">{{userInfo.nickName}}</view>
					<view class="firstText2">
						<view class="textBox1" v-if="idCard">
							<image src="../../static/my7.png" class="myImg7" />
							<view style="margin: 0 8rpx;">已认证</view>
						</view>
						<view class="textBox2" @click="onCopy">
							<image src="../../static/my9.png" class="myImg9" />
							<view>{{userInfo.clientUserId}}</view>
							<image src="../../static/my8.png" class="myImg8" />
						</view>
					</view>
				</view>
			</view>
			<view v-if="userInfo" class="firstView3" @click="onNav('/pages/personal/index')">查看</view>
		</view>
		<view class="second">
			<!-- <view class="secondBox" @click="onNav('/pages/submitCarInfo/index')">
				<view class="smallBox">
					<image src="../../static/my1.png" class="secondImg" />
					<view>爱车评估</view>
				</view>
				<uni-icons type="right" size="15" color="#999"></uni-icons>
			</view> -->
			<!-- <view class="secondBox" @click="onNav('/pages/submitCarInfo/index')">
				<view class="smallBox">
					<image src="../../static/my2.png" class="secondImg" />
					<view>额度评估</view>
				</view>
				<uni-icons type="right" size="15" color="#999"></uni-icons>
			</view> -->
			<!-- <view class="secondBox" @click="onNav('/pages/realName/index')">
				<view class="smallBox">
					<image src="../../static/my3.png" class="secondImg" />
					<view>实名认证</view>
				</view>
				<uni-icons type="right" size="15" color="#999"></uni-icons>
			</view> -->
			<view class="secondBox" @click="onNav(`/pages/aboutMy/index?title=关于我们&type=4`)">
				<view class="smallBox">
					<image src="../../static/my4.png" class="secondImg" />
					<view>关于我们</view>
				</view>
				<uni-icons type="right" size="15" color="#999"></uni-icons>
			</view>
			<view class="secondBox" @click="showModal = true">
				<view class="smallBox">
					<image src="../../static/my5.png" class="secondImg" />
					<view>客服电话</view>
				</view>
				<uni-icons type="right" size="15" color="#999"></uni-icons>
			</view>
			<view class="secondBox" @click="onNav('/pages/set/index')">
				<view class="smallBox">
					<image src="../../static/my6.png" class="secondImg" />
					<view>设置</view>
				</view>
				<uni-icons type="right" size="15" color="#999"></uni-icons>
			</view>
		</view>
		<TabBer currentPath="/pages/my/index" />
		<view class="modal" v-if="showModal">
			<view class="mian">
				<view class="head_top">
					<view class="left_box">
						<view>客服电话</view>
						<uni-icons @click="showModal = false" type="closeempty" size="24"></uni-icons>
					</view>
					<view class="time">工作日 10:00-18:00</view>
				</view>
				<view class="center" style="font-size: 50rpx;">
					15156269848（微信同号）
				</view>
				<view class="btn" @click="makePhone" >
					立即拨打电话
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getUserInfo
	} from '../../api/login';
	import {
		bindToken
	} from '../../utils/request';
	export default {
		components: {},
		onLoad(option) {},
		data() {
			return {
				determine: false,
				scrollTop: 0,
				userInfo: null,
				idCard: undefined,
				isLoginStatus: false,
				showModal: false,
			}
		},
		onPageScroll({
			scrollTop
		}) {
			this.scrollTop = scrollTop;
		},
		async onShow() {
			const data = await bindToken('getToken');
			console.log(data,'data')
			if (data && data.cyrappToken ) this.isLoginStatus = true;
			if (this.isLoginStatus) {
				getUserInfo().then(({
					data
				}) => {
					this.userInfo = data.CyrappUserInfo;
					this.idCard = data.clientUser.idcardNumber;
				})
			}
		},
		methods: {
			makePhone(){
				let that = this;
				uni.makePhoneCall({
					phoneNumber:'15156269848',
					complete() {
						that.showModal = false
					}
				})
			},
			onNav(url) {
				if (this.isLoginStatus) {
					uni.navigateTo({
						url
					})
				} else {
					uni.navigateTo({
						url: '/pages/login/index'
					})
				}
			},
			onCopy() {
				uni.setClipboardData({
					data: String(this.userInfo.clientUserId),
					success: () => {
						uni.showToast({
							title: '复制成功',
							icon: 'success'
						})
					},
					fail(err) {
						console.log(err, 'err========>')
					}
				})
			}
		}
	}
</script>
<style>
	page {
		background-color: #F5F7FA;
	}
</style>
<style lang="less" scoped>
	@import './index.less';
</style>